<?php
class Localization
{
	private static $languages = null;
	
	private static $data = array();

	public static function setFile($filename, $length = 1024, $delimiter = ',', $enclosure = '"')
	{
		if (is_file($filename)) {
			$handle = fopen($filename, 'r');
			
			foreach (fgetcsv($handle, $length, $delimiter, $enclosure) as $data_k => $data_v) {
				if (!empty($data_v)) {
					self::$languages[$data_v] = $data_k;
				}
			}
			
			while (($data = fgetcsv($handle, $length, $delimiter, $enclosure)) !== FALSE) {
				$data[0] = explode(',', $data[0]);
				self::$data[] = $data;
			}
			
			fclose($handle);
		}
	}

	public static function getData($name)
	{
		$data = array();

		if (!is_null(self::$data)) {
			foreach (self::$data as $data_k => $data_v) {
				if (in_array($name, $data_v[0])) {
					$data[$data_v[1]] = array();
					
					foreach (self::$languages as $language_k => $language_v) {
						$data[$data_v[1]][$language_k] = $data_v[$language_v];
					}
				}
			}
		} else {
			return false;
		}

		return $data;
	}
}
?>